﻿<?php
session_start();
if(!empty($_COOKIE['username'])){
	$username=$_COOKIE['username'];
	$passworder=$_COOKIE['password'];
	login($username,$password);
}
if (isset($_POST['submit'])) {
	$username=trim($_POST['username']);
	$password=trim($_POST['password']);
	if (empty($_POST['username'])||empty($_POST['password'])) {
		echo "用户名或密码不能为空！";
	} else {
		login($username,$password);
		setcookie('username',$_SESSION['username'],time()+3600);
		setcookie('password',$_SESSION['username'],time()+3600);
	}
} else {
	if ($_GET['logout']=='logout') {
		unset($_SESSION['username']);
		unset($_SESSION['password']);
		setcookie('username','');
		setcookie('password','');
		header('location:login.html');
	} 
}
function login($username,$pass){
	$password=md5('$pass');
	include_once('db.php');
	$sql="select * from guest where username='$username'and password='$password'";
	$db=new DB();
	$user=$db->get($sql);
	echo "<pre>";
	if (empty($user)) {
		echo "该用户不存在或密码错误!";
	} else {
		# code...
	}
	
}
?>